<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {margin: 0;overflow: hidden;}
    #canvas {background-color: antiquewhite;}
  </style>
</head>
<body>
  <canvas id="canvas"></canvas>
  <script>
    /** @type {HTMLCanvasElement} */
    const canvas = document.querySelector('#canvas');
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
    const ctx = canvas.getContext('2d');

    /*
    * 图片尺寸：宽，高
    * */
    const [width, height] = [400,200];

    /*
    ImageData() 对象的建立
    new ImageData(Uint8ClampedArray, width, heidth)
    new ImageData( width, heidth)
    * */
    /* const imgDt = new ImageData(width, height);
    console.log(imgDt); */

    /*
    ImageData() 对象的建立
    ctx.createImageData(width, heidth)
    ctx.createImageData(ImageData)
    * */
    const imgDt = ctx.createImageData(width, height);
    console.log(imgDt);

    imgDt.data.forEach((ele,ind) => {
      imgDt.data[ind] = 255;
    });
    ctx.putImageData(imgDt, 0, 0);

    /*
    获取canvas 中的像素
    getImageData(x, y, width, height)
    * */
    const canvasImgDt = ctx.getImageData(0,0,1,1);
    console.log(canvasImgDt)

  </script>
</body>
</html>